﻿// See https://aka.ms/new-console-template for more information
using SequentialGuid;

Console.WriteLine("Hello, World!");

var db = new MyDbContext();
var users = new List<User>();
var guidGenerator = new SequentialGuidGenerator();

for (int i = 0; i < 10; i++)
{
    var id = guidGenerator.Create(SequentialGuidType.SequentialAtEnd);
    //var id = Guid.NewGuid();
    var user = new User { Id = id, Name = $"test{i}", CreateTime = DateTime.Now };
    users.Add(user);
    Console.WriteLine(user);
    Thread.Sleep(100);
}

db.AddRange(users);
db.SaveChanges();

// 内存排序是字符排序，与 SqlServer 的排序是不同的
Console.WriteLine("...内存排序结果...");
users.OrderBy(a => a.Id).ToList().ForEach(item =>
  {
      Console.WriteLine(item);
  });

Console.WriteLine("...数据库排序结果...");
var temp = db.Users.OrderBy(a => a.Id).ToList();
temp.ForEach(user =>
{
    Console.WriteLine(user);
});